<template>
    <div>
        <div class="header">
            <HeaderTop/>
            <Breadcrumb :info="info"/>
        </div>
        <div class="main">
            <el-row>
                <el-col :span="6" :offset="2">
                    <img src="../../../../static/images/shop/login-png.png"  alt="">
                </el-col>
                <el-col :span="8" :offset="4">
                    
                    <el-form :model="ruleForm" status-icon :rules="rules" label-width="100px" class="demo-ruleForm">
                        <el-form-item>
                            <p class="title">登录</p>
                        </el-form-item>
                        <el-form-item prop="phone">
                            <el-input type="text" v-model="ruleForm.phone" autocomplete="off" placeholder="输入手机号码:15976912781"></el-input>
                        </el-form-item>
                        <el-form-item  prop="pass">
                            <el-input type="password" v-model="ruleForm.pass" autocomplete="off" placeholder="输入密码:123"></el-input>
                        </el-form-item>
                        <el-form-item class="form-bottom">
                            <el-button class="form-btn el-icon-circle-check-outline" type="primary" @click="submitForm()">登录</el-button>
                        </el-form-item>
                        <el-form-item>
                            <div class="text">
                                <span>忘记密码</span>
                                <span>新用户</span>
                            </div>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>
        </div>
    </div>
</template>

<script>
import HeaderTop from '../../HeaderTop/HeaderTop.vue';

 export default {
    name:'LoginPage',
    components:{
        HeaderTop
    },
    data() {
        let validatePhone = (rule, value, callback) => {
            if (value === '') {
            callback(new Error('请输入手机号'));
            }else if( !/^1[0-9]{10}$/.test(value)){
                callback(new Error('请输入正确的手机号格式'))
            }
            callback();
        };
      return {
        info:{
            title:'用户登录',
            label:['首页','用户登录']
        },
        ruleForm: {
          phone: '',
          pass: '',
        },
        rules: {
          phone: [
            {validator:validatePhone, trigger: 'blur' }
          ],
          pass: [
            {required:true,message:'请输入密码',trigger:'blur'},
          ],
        }
      };
    },
    methods: {
      submitForm() {
          let { phone,pass} = this.ruleForm
          if ( pass === '123'){
              this.$message({
                  type:'success',
                  message:'登录成功'
              })
              localStorage.setItem('userName',phone)
              this.$router.push({  path:'/home'})
              return
          }
          this.$message.error('登录失败')
      },
    }
  }
</script>

<style scoped>
.el-form{
    margin-bottom: 0px;
}
.header-top{
    padding: 0 60px;
    overflow: hidden;
    height: 101px;
}
.img{
    width: 200px;
    height: 50px;
    line-height: 101px;
}

.input{
    width: 500px;
}
.form{
    padding: 30px 10px 0 10px ;
}
.main{
    margin-top: 40px;
}
.title{
    margin: 0px;
    font-size: 16px;
    color: black;
}
.form-btn{
    width: 100%;
}
.form-bottom{
    margin-bottom: 0px;
}
.text{
    text-align: center;
}
.text span{
    color: #F07057;
}
.text span:hover{
    color: black;
}
</style>